Skip to content

Fix cc_common.link runtime library selection - #4225

Open
KirillTim wants to merge 1 commit into
bazelbuild:mainfrom
KirillTim:try_to_fix_cc_common_link
Open

KirillTim wants to merge 1 commit into
bazelbuild:mainfrom
KirillTim:try_to_fix_cc_common_link

Conversation

@KirillTim

Copy link
Copy Markdown
Contributor

Summary

  • honor --dynamic_mode=fully when calling cc_common.link
  • add Starlark analysis tests for runtime selection and shared link_deps
  • compare Rust linkage behavior with equivalent cc_binary targets

Why

cc_common.link defaults link_deps_statically to true. Rust targets therefore selected the static C++ runtime even under fully dynamic linking.

Impact

Rust targets using cc_common.link now select the dynamic C++ runtime when built with --dynamic_mode=fully, matching cc_binary behavior.

Validation

$bazel test //...
...
Executed 578 out of 608 tests: 578 tests pass and 30 were skipped.

This is a follow-up to 226c488

## Summary

- honor `--dynamic_mode=fully` when calling `cc_common.link`
- add Starlark analysis tests for runtime selection and shared `link_deps`
- compare Rust linkage behavior with equivalent `cc_binary` targets

## Why

`cc_common.link` defaults `link_deps_statically` to true. Rust targets
therefore selected the static C++ runtime even under fully dynamic linking.

## Impact

Rust targets using `cc_common.link` now select the dynamic C++ runtime
when built with `--dynamic_mode=fully`, matching `cc_binary` behavior.

## Validation

```
$bazel test //...
...
Executed 578 out of 608 tests: 578 tests pass and 30 were skipped.
```

This is a follow-up to 226c488
@slackito
slackito requested a review from krasimirgg August 27, 2026 17:23

@krasimirgg krasimirgg left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thank you, this is very nice!

I think there may be a couple of other stray places where we need to plumb these cc-std-dylibs for this setup to work. Could you add a toy example like a rust_binary that depends on a cc_library that exercises the C++ stdlib, and a test that runs the rust_binary under --dynamic_mode=fully (e.g., via a user-defined transition), ensuring that it succeeds at runtime (so the necessary cc-std-dylibs are appropriately made available to the rust binary at dynamic-link-time? -- and if that setup doesn't match your intended real use case please let me know :)

@krasimirgg krasimirgg added the awaiting-response Maintainers have responded to the pull-request or thread and now await contributor responses. label Sep 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-response Maintainers have responded to the pull-request or thread and now await contributor responses.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants